import mysql.connector
import json

# 创建与数据库的连接
cnx = mysql.connector.connect(
    host="127.168.80.190",
    port=3306,
    user="root",
    password="12345678",
    database="gaokao",
    use_pure=True,
    ssl_disabled=True
)

# 创建一个游标对象
cursor = cnx.cursor()

# 定义要执行的 SQL 插入语句

with open('json/majorBasics.json', 'r', encoding='utf-8') as f:
    data = json.load(f)


for key, value in data.items():
    insert_query = "INSERT INTO majorBasic (sp_code, name, hot, year, degree, belong, sp_level) VALUES (%s, %s, %s, %s, %s, %s, %s)"
    insert_data = (key, value['name'], value['hot'], value['year'], value['degree'], value['belong'], value['level'])
    cursor.execute(insert_query, insert_data)
    cnx.commit()

# 关闭游标和数据库连接
cursor.close()
cnx.close()
